<?php

namespace App\Enums;

class GenderEnum
{
    const GENDER_OPTIONS = [
        ['gender' => 0, 'text' => 'Unknown'],
        ['gender' => 1, 'text' => 'Male'],
        ['gender' => 2, 'text' => 'Female']
    ];

    /**
     * 获取所有性别的文本映射
     *
     * @return array
     */
    public static function getAll(): array
    {
        return array_column(self::GENDER_OPTIONS, "text", 'gender');
    }

    /**
     * 根据性别值获取对应的文本
     *
     * @param int $gender 性别值
     * @return string|null 对应的文本或null
     */
    public static function getText(int $gender): ?string
    {
        $texts = self::getAll();
        return $texts[$gender] ?? null;
    }
}
